/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.zx.user.agreement.web;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.mybatis.mapper.query.QueryType;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.sys.entity.Area;
import com.jeesite.modules.sys.service.AreaService;
import com.jeesite.modules.zx.user.agreement.entity.TuserAgreement;
import com.jeesite.modules.zx.user.agreement.service.TuserAgreementService;

/**
 * 用户协议条款Controller
 * @author zpp
 * @version 2020-02-27
 */
@Controller
@RequestMapping(value = "${adminPath}/zx/user/agreement/tuserAgreement")
public class TuserAgreementController extends BaseController {

	@Autowired
	private TuserAgreementService tuserAgreementService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public TuserAgreement get(String id, boolean isNewRecord) {
		return tuserAgreementService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("zx:user:agreement:tuserAgreement:view")
	@RequestMapping(value = {"list", ""})
	public String list(TuserAgreement tuserAgreement, Model model,HttpServletRequest request,HttpServletResponse response) {
		
//		List<String> list=new ArrayList<String>();
//		list.add("110112000000");
//		list.add("110112001000");
//		list.add("110112002000");
//		list.add("110112003000");
//		list.add("110112004000");
//		list.add("110112005000");
//		list.add("110112006000");
//		list.add("110112007000");
//		list.add("110112008000");
//		list.add("110112009000");
//		areedf.getSqlMap().getWhere().and("parent_code", QueryType.IN, list);
		
		model.addAttribute("tuserAgreement", tuserAgreement);
		return "modules/zx/user/agreement/tuserAgreementList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("zx:user:agreement:tuserAgreement:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<TuserAgreement> listData(TuserAgreement tuserAgreement, HttpServletRequest request, HttpServletResponse response) {
		tuserAgreement.setPage(new Page<>(request, response));
		Page<TuserAgreement> page = tuserAgreementService.findPage(tuserAgreement);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("zx:user:agreement:tuserAgreement:view")
	@RequestMapping(value = "form")
	public String form(TuserAgreement tuserAgreement, Model model) {
		model.addAttribute("tuserAgreement", tuserAgreement);
		return "modules/zx/user/agreement/tuserAgreementForm";
	}

	/**
	 * 保存用户协议条款
	 */
	@RequiresPermissions("zx:user:agreement:tuserAgreement:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated TuserAgreement tuserAgreement) {
		tuserAgreementService.save(tuserAgreement);
		return renderResult(Global.TRUE, text("保存用户协议条款成功！"));
	}
	
	/**
	 * 停用用户协议条款
	 */
	@RequiresPermissions("zx:user:agreement:tuserAgreement:edit")
	@RequestMapping(value = "disable")
	@ResponseBody
	public String disable(TuserAgreement tuserAgreement) {
		tuserAgreement.setStatus(TuserAgreement.STATUS_DISABLE);
		tuserAgreementService.updateStatus(tuserAgreement);
		return renderResult(Global.TRUE, text("停用用户协议条款成功"));
	}
	
	/**
	 * 启用用户协议条款
	 */
	@RequiresPermissions("zx:user:agreement:tuserAgreement:edit")
	@RequestMapping(value = "enable")
	@ResponseBody
	public String enable(TuserAgreement tuserAgreement) {
		tuserAgreement.setStatus(TuserAgreement.STATUS_NORMAL);
		tuserAgreementService.updateStatus(tuserAgreement);
		return renderResult(Global.TRUE, text("启用用户协议条款成功"));
	}
	
	/**
	 * 删除用户协议条款
	 */
	@RequiresPermissions("zx:user:agreement:tuserAgreement:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(TuserAgreement tuserAgreement) {
		tuserAgreementService.delete(tuserAgreement);
		return renderResult(Global.TRUE, text("删除用户协议条款成功！"));
	}
	
}